package com.example.gmapsdemo;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class CreateSportEvent extends Activity {
	ImageButton newEventTypePic;
	static EditText newEventTitel;

	private static int _year;
	private static int _month;
	private static int _day;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_sport_event);

		newEventTypePic = (ImageButton) findViewById(R.id.newEventTypePic);
		newEventTitel = (EditText) findViewById(R.id.newEventTitle);

		final Calendar c = Calendar.getInstance();
		_year = c.get(Calendar.YEAR);
		_month = c.get(Calendar.MONTH);
		_day = c.get(Calendar.DAY_OF_MONTH);

		newEventTypePic.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				DialogFragment newFragment = new DatePickerFragment();
				newFragment.show(getFragmentManager(), "datePicker");
			}
		});
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent backToMain = new Intent(this, FindMe.class);
		switch (item.getItemId()) {

		case R.id.newEventOk:
			Toast.makeText(this, "Create new Event selected",
					Toast.LENGTH_SHORT).show();
			startActivity(backToMain);
			break;
		// action with ID action_settings was selected
		case R.id.newEventCancel:
			startActivity(backToMain);
		default:
			break;
		}

		return true;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.create_sport_event, menu);
		return true;
	}

	public static class DatePickerFragment extends DialogFragment implements
			DatePickerDialog.OnDateSetListener {

		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState) {
			// Create a new instance of DatePickerDialog and return it
			return new DatePickerDialog(getActivity(), this, _year, _month,
					_day);
		}

		@Override
		public void onDateSet(DatePicker view, int year, int month, int day) {
			_year = year;
			_month = month;
			_day = day;
			System.out.println(day + "." + month + "." + year);
			newEventTitel.setText(day + "." + month + "." + year);
		}
	}

}
